<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
  <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all" />
  <link rel="stylesheet" href="__CSS__/admin.css"  media="all">
  <link rel="stylesheet" href="__CSS__/tpcitrix.css"  media="all">
  <style type="text/css">
    td input
    {
        border-radius: 5px;padding: 4px 5px;border: 1px solid #b6b6b6;
    }
    .link_img
    {
        padding:0px;text-align: center;
    }
    .link_img img
    {
        height: 30px;
    }
    .show_order
    {
        width: 50px;text-align: center;
    }
    #tooltip{
      position:absolute;
      border:1px solid #ccc;
      background:#333;
      padding:2px;
      display:none;
      color:#fff;
    }
  </style>
</head>
<body class="patch_body">
<div class="tplay-body-div">
    <div class="layui-tab">
      <ul class="layui-tab-title">
        <li class="layui-this">链接列表</li>
        <li><a href="{:url('admin/Link/link_publish')}" class="a_menu">新增链接</a></li>
      </ul>
    </div> 
    {notempty name="link"}
    <div class="layui-form">
      <table class="layui-table">
        <colgroup>
          <col width="280">
          <col width="280">
          <col width="100">
          <col width="100">
          <col>
        </colgroup>
        <thead>
          <tr style="background-color: #ECECEC;">
            <th>链接名称</th>
            <th>链接地址</th>
            <th>链接LOGO</th>
            <th>显示顺序</th>
            <th>操作</th>
          </tr> 
        </thead>
        <tbody>
          {volist name="link" id="vo"}
          <tr>
            <td ><input type="text" value="{$vo.link_name}" onblur="changeTableVal('link','id','{$vo.id}','link_name',this,'text')"></td>
            <td ><input type="text" value="{$vo.link_url}" onblur="changeTableVal('link','id','{$vo.id}','link_url',this,'url')"></td>
            <td class="link_img"><a href="{$vo.link_thumb|geturl}" class="tooltip"><img src="{$vo.link_thumb|geturl}"  ></a></td>
            <td><input type="text" value="{$vo.show_order}" onblur="changeTableVal('link','id','{$vo.id}','show_order',this,'number')" class="show_order"></td>
            <td>   
                <button class="layui-btn layui-btn-xs"><a href="{$vo.link_url}" target="_blank" style="color: #FFF;">查看</a></button>
                <button class="layui-btn layui-btn-xs layui-btn-normal"><a href="{:url('admin/Link/link_publish',['id'=>$vo.id])}" style="color: #FFF;">编辑</a></button>
                <button class="layui-btn layui-btn-xs layui-btn-danger delete" id="{$vo.id}">删除</button>
            </td>
          </tr>
          {/volist}
        </tbody>
      </table>
      <div style="padding:0 20px;">{$link->render()}</div>
      {else}
      <h5 style="padding: 50px;">数据走失咯！快去添加吧</h5>
      {/notempty}
     {include file="public/foot"}
      <script type="text/javascript">
      $('.delete').click(function(){
        var id = $(this).attr('id');
        layer.confirm('确定要删除?', function(index) {
          $.ajax({
            url:"{:url('admin/Link/link_delete')}",
            data:{id:id},
            dateTyoe:"json",
            type:'post',
            success:function(res) {
              layer.msg(res.msg);
              if(res.code == 1) {
                setTimeout(function(){
                  location.href = res.url;
                },1500)
              }
            }
          });
        });
      });
      function changeTableVal(table,id_name,id_value,field,obj,is_where)
      { 
            var value = $(obj).val();
            switch(is_where)
            {
            case 'url':
                if(checkUrl(value) == false)
                {
                    layer.msg('请输入正确网址');
                    return false;
                }
              break;
            case 'number':
                var reg = /^[0-9]*$/;
                if(!reg.test(value))
                {
                    layer.msg('请输入正整数');
                    return false;
                }
              break;
            }
            $.ajax({
                url:"{:url('admin/Link/link_changeTableVal')}",
                data:{'table':table,'id_name':id_name,'id_value':id_value,'field':field,'value':value},
                type:'post',
                async: false,
                dateTyoe:"json",
                success:function(res) {
                  layer.msg(res.msg);
                  //console.log(res)
                }
            });
      }
      //验证码url
    function checkUrl(urlString){
        if(urlString!=""){
            var reg=/(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/;
            if(!reg.test(urlString)){
                return false;
            }
        }
        return true;
    }
    </script>
    </div>
</div>
</body>
</html>